<%@page import="avaliacao.jsp.model.Leilao"%>
<%@ page import="avaliacao.jsp.model.Usuario"%>
<%@ page language="java"%>
<%
	Usuario usr = (Usuario) session.getAttribute("usr");
	if (usr == null) {
		response.sendRedirect("../index.jsp?erro=informarNome");
		return;
	}
	String stId = request.getParameter("id");
	String stValor = request.getParameter("lance");
	if (stId!=null && !stId.equals("") && stValor!=null && !stValor.equals("")) {
		int id = -1;
		double valor = -1;
		try {
			id = Integer.parseInt(stId);
			valor = Double.parseDouble(stValor);
			Leilao leilao = Leilao.getInstance();
			boolean ok = leilao.processarLance(id, valor, usr);
			if (!ok) {
				response.sendRedirect("../paginaPrincipal.jsp?erro=lanceInvalido");
				return;
			}
		} catch(NumberFormatException nfex) {
			response.sendRedirect("../paginaPrincipal.jsp?erro=nfex");
			return;
		}
	}
	response.sendRedirect("../paginaPrincipal.jsp");
	return;
%>